package landx.toolkit.config
{
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	
	import landx.toolkit.Console;
	import landx.toolkit.utils.StringUtil;

	/**
	 * 通过反射太更改系统静态变量的配置 
	 * @author Administrator
	 * 
	 */	
	public class ReflectionConfig
	{
		private var m_table:Dictionary=new Dictionary();
		
		public function ReflectionConfig():void{
			
		}
		
		/**
		 * 注册class ,为了保证类在使用反射前已经被使用
		 * @param classx 注册的类
		 */		
		public function regClass(classx:Class):void{
			var className:String= getQualifiedClassName(classx);
			className=StringUtil.replace(className,"::",".");
			m_table[className]=classx;
		}
		
		/**
		 * 设置指定类的指定变量的数值 
		 * @param refName
		 * @param value
		 */		
		public function setValue(refName:String,value:String):void{
			var index:int=StringUtil.replace(refName,"::","").lastIndexOf(".");
			var className:String=refName.substring(0,index);
			var varx:String=refName.substring(index+1,refName.length);
			if(m_table[className]!=undefined){
				try{
					m_table[className][varx]=value;
				}catch(e:Error){
					Console.Write("Error: {0} - {1}",e.message,refName);
				}
			}else{
				Console.Write("Error: {0} - {1}","类名未定义",refName);
			}
		}
	}
}